package com.jiuyin.dianjing.util;


import android.content.Context;
import android.widget.Toast;

import androidx.annotation.StringRes;

import com.jiuyin.dianjing.app.HelperApplication;

/**
 * @author zy
 * @date 2017/4/7
 */

public class ToastUtil {
    private static Context mContext = HelperApplication.getContext();

    public static void showLong(@StringRes int resId) {
        getToast(resId, Toast.LENGTH_SHORT).show();
    }

    public static void showLong(String message) {
        getToast(message, Toast.LENGTH_SHORT).show();
    }

    public static void showShort(@StringRes int resId) {
        getToast(resId, Toast.LENGTH_SHORT).show();
    }

    public static void showShort(String message) {
        getToast(message, Toast.LENGTH_SHORT).show();
    }

    private static Toast getToast(@StringRes int resId, int length) {
        if (null == mContext) {
            LogUtil.log("context is null");
            throw new RuntimeException("context must be not null");
        }
        return Toast.makeText(mContext, mContext.getText(resId), length);
    }

    private static Toast getToast(String message, int length) {
        if (null == mContext) {
            LogUtil.log("context is null");
            throw new RuntimeException("context must be not null");
        }
        return Toast.makeText(mContext, message, length);
    }
}
